﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TRPOP.Common;

namespace TRPOP.CRM.Component
{
    /// <summary>
    /// 系统基本信息
    /// </summary>
    [Serializable]
    public class SystemInfo
    {
        #region 私有变量
        private string m_SystemName = "CRM管理系统";
        private string m_DataBaseConnection = @"server=.;database=TRPOP_CRM;uid=sa;pwd=123456;pooling=true;Min Pool Size=50;Max Pool Size=100;Connect Timeout=60";
        #endregion

        #region 成员函数
        
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public string DataBaseConnection
        {
            get { return m_DataBaseConnection; }
            set { m_DataBaseConnection = value; }
        }

        /// <summary>
        /// 系统名称
        /// </summary>
        public string SystemName
        {
            get { return m_SystemName; }
            set { m_SystemName = value; }
        }

        #endregion
    }

    /// <summary>
    /// 获取当前的系统基本信息
    /// </summary>
    public static class SystemInfoHelper
    {
        private static SystemInfo mSystemInfo;

        /// <summary>
        /// 获取系统信息
        /// </summary>
        /// <returns></returns>
        public static SystemInfo getSystemInfo()
        {
            if (mSystemInfo == null)
            {
                setSystemInfo();
            }
            return mSystemInfo;
        }

        /// <summary>
        /// 设置系统信息
        /// </summary>
        private static void setSystemInfo()
        {
            string strFileName = Util.GetMapPath("/SystemInfo.config");
            object obj = null;
            if (FileUtil.IsExist(strFileName))
            {
                try
                {
                    obj = SerializationHelper.Load(typeof(SystemInfo), strFileName);
                }
                catch
                {
                    obj = null;
                }
                finally
                {
                    if (obj is SystemInfo == false || obj == null)
                    {
                        obj = new SystemInfo();
                        SerializationHelper.Save(obj, strFileName);
                    }
                    mSystemInfo = obj as SystemInfo;
                }
            }
            else
            {
                mSystemInfo = new SystemInfo();
                SerializationHelper.Save(mSystemInfo, strFileName);
            }
        }

        /// <summary>
        /// 重置系统信息
        /// </summary>
        public static void ReSetSystemInfo()
        {
            mSystemInfo = null;
        }
    }
}
